<template>
	<div>
		<div class="father">
			<div class="son"></div>
		</div>
		<el-button type="primary" @click="pushMethod">push</el-button>
		<el-button type="primary" @click="foreach">foreach</el-button>
		<el-button type="primary" @click="every">every</el-button>
		<el-button type="primary" @click="filter">filter</el-button>
		<el-button type="primary" @click="find">find</el-button>
		<el-button type="primary" @click="splice">splice</el-button>
		<el-button type="primary" @click="slice">slice</el-button>
		<el-button type="primary" @click="indexOf">indexOf</el-button>
		<el-button type="primary" @click="map">map</el-button>
		<el-button type="primary" @click="constructor">构造函数</el-button>
	</div>
</template>

<script>
	import { getSum, args } from '@/utils/index'
	export default {
		data() {
			return {
				key: '',
				arr: [1, 2, 3, 4, 5],
				arr1: [10, 11]
			}
		},
		created() {},
		methods: {
			constructor() {
				console.log([1, 2, 3])
				// let obj = { a: 1, b: 2 }
				for (const key in [3, 4, 5]) {
					console.log(key)
				}
				// console.log(obj)
				// function Star(name, age) {
				//   (this.name = name),
				//     (this.age = age),
				//     (this.sing = function(sang) {
				//       console.log(sang)
				//     })
				// }
				// const doen = new Star('doen', 18)
				// console.log(doen)
			},
			splice() {
				getSum(1, 100)
				args(this.arr)
				// console.log(sum)
				// console.log(sum)
				// let a = this.arr.splice(2, 1)
				// console.log(this.arr)
				// console.log(a)
			},
			slice() {
				let a = this.arr.slice(0, 2)
				console.log(a)
			},
			indexOf() {
				// 存在的
				let a = this.arr.indexOf(5)
				console.log(a)
				// 不存在的
				let b = this.arr.indexOf(9)
				console.log(b)
			},
			map() {
				let a = this.arr.map(item => {
					return item + 1
				})
				console.log(a)
			},
			pushMethod() {
				this.arr.push(...this.arr1)
				console.log(this.arr)
				// let a = this.arr.push(9)
				// // this.$set(this.arr, 5, 9)
				// console.log(a);
				const arr = [1, 2, 3]
				const [first, two] = arr
				console.log(first, two)
			},
			foreach() {
				// 遍历数组
				let a = this.arr.forEach(item => {
					console.log(item)
					return item
				})
				console.log(a)
			},
			every() {
				// 为真继续循环，为假则终止循环
				let a = this.arr.every(item => {
					console.log(item)
					return item >= 3
				})
				console.log(a)
			},
			filter() {
				// 返回满足条件的数组
				let a = this.arr.filter(item => {
					console.log(item)
					return item >= 2
				})
				console.log(a)
			},
			find() {
				// 返回满足条件的值
				let a = this.arr.find(item => {
					console.log(`内部的：${item}`)
					return item >= 2
				})
				console.log(a)
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import './style.scss';
</style>
